package com.lr.wfxmanager.merchant.service.impl;

import com.lr.wfxmanager.merchant.bean.GoodsTypeBean;
import com.lr.wfxmanager.merchant.bean.WxbGood;
import com.lr.wfxmanager.merchant.mapper.GoodsMapper;
import com.lr.wfxmanager.merchant.service.IGoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class GoodsServiceImpl implements IGoodsService {
    @Resource
    private GoodsMapper goodsMapper;
    /*查询商品类型树*/
    @Override
    public List<GoodsTypeBean> queryGoodsType() {
        List<GoodsTypeBean> goodsTypeBeans = goodsMapper.queryGoodsType();
        return goodsTypeBeans;
    }
    /*商品列表*/
    @Override
    public List<WxbGood> queryGoodsList(Integer currentPage) {
        //查询所有
        List<WxbGood> allGoods = goodsMapper.queryGoodsList();
        //每页显示4条
        List<WxbGood> wxbGoods = new ArrayList<>();
        int end = currentPage*4 > allGoods.size()?allGoods.size():currentPage*4;
        for (int i = (currentPage-1)*4;i<end;i++){
            wxbGoods.add(allGoods.get(i));
        }
        wxbGoods.get(0).setSize(allGoods.size());//临时保存下所有商品数
        return wxbGoods;
    }
    //修改产品state
    @Override
    public void updateGoodsState(Integer flag, String[] gid) throws Exception{
        goodsMapper.updateGoodsState(flag, gid);
    }
}
